package com.example.mymenu.manager;

import android.database.Cursor;
import android.util.Log;

import com.example.mymenu.bean.MyAskBean;
import com.example.mymenu.bean.MyTakeBean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DataManager {
    private String[] title = {"热门", "场景"};
    private Map<String, List<String>> information;

    public DataManager() {
        information = new HashMap<>();
        List<String> list1 = new ArrayList<>();
        List<String> list2 = new ArrayList<>();
        list1.add("家常菜");
        list1.add("下饭菜");
        list2.add("小龙虾");
        list2.add("午餐");
        information.put(title[0], list1);
        information.put(title[1], list2);
    }

    //网络请求访问的数据
    public String internetFindMessage() {
        String returnMessage = "";
        for (int i = 0; i < title.length; i++) {
            for (int j = 0; j < information.get(title[i]).size(); j++) {
                if (i == title.length - 1 && j == information.get(title[i]).size() - 1) {
                    returnMessage = returnMessage + information.get(title[i]).get(j);
                } else {
                    returnMessage = returnMessage + information.get(title[i]).get(j) + "#";
                }
            }
        }
        return returnMessage;
    }

    //返回标题
    public String[] getTitleMessage() {
        return title;
    }

    //返回按钮Text值
    public Map<String, List<String>> getInformation() {
        return information;
    }

    //从游标cursor中获取菜谱基本信息
    public List<String> getInfoFromCursor(Cursor cursor) {
        List<String> returnMessage = new ArrayList<>();
        String msg = "";
        if (cursor.moveToFirst()) {
            for (int i = 1; i < 4; i++) {
                msg = cursor.getString(i).replace("<br />", "\n");
                returnMessage.add(msg);
            }
            msg = cursor.getString(4).replace("#", "  ");
            returnMessage.add(msg);
        }
        return returnMessage;
    }

    //从游标中获取菜谱步骤
    public String[] getStepFromCursor(Cursor cursor) {
        String msg = "";
        if (cursor.moveToFirst()) {
            msg = cursor.getString(5).replace("<br />", "\n");
        }
        String[] returnMessage = msg.split("#");
        return returnMessage;
    }

    //更改请求体信息
    public MyAskBean updateAskBean(String findMessage) {
        MyAskBean myAskBean = new MyAskBean();
        myAskBean.setCode(0);
        myAskBean.setMultiStatus("0");
        myAskBean.setMsg(findMessage);
        myAskBean.setPageSize(5);
        myAskBean.setPageNum(1);
        myAskBean.setOpenPage(1);
        myAskBean.setSrialNumber("ergdfgdg");
        return myAskBean;
    }

    //获取步骤图片信息
    public String getStepImageMessage(MyTakeBean.PayloadBean.ListItemsBean listItemsBean) {
        List<MyTakeBean.PayloadBean.ListItemsBean.ProcessBean> processBeanList = listItemsBean.getProcess();
        String returnMsg = "";
        for (int i = 0; i < processBeanList.size(); i++) {
            String pic = processBeanList.get(i).getPic();
            if (i == processBeanList.size() - 1) {
                returnMsg = returnMsg + pic;
            } else {
                returnMsg = returnMsg + pic + "#";
            }
        }
        return returnMsg;
    }

    //获取游标中步骤图片信息
    public String[] getStepImageFromCursor(Cursor cursor){
        String[] returnMessage = new String[]{};
        if (cursor.moveToFirst()) {
            returnMessage = cursor.getString(7).split("#");
        }
        return returnMessage;
    }


}
